package com.company;

import java.util.*;
import java.util.Collections;
import java.util.ArrayList;
public class Main {

    static ArrayList<StudentScore>studentScores
    =new ArrayList<>();
    public static void main(String[] args) {
        // write your code here
        studentScores.add(new StudentScore("001", "张三", "男", 90, 85, 88));
        studentScores.add(new StudentScore("002", "李四", "女", 78, 92, 91));
        studentScores.add(new StudentScore("003", "王五", "男", 88, 76, 89));
        studentScores.add(new StudentScore("004", "赵六", "女", 95, 89, 94));
//        Collections.addAll(studentScores);
        showAll();
//        尝试将Collections.max()方法直接用于ArrayList<StudentScore>类型的对象失败
//        int maxlgg= Collections.max(showAll(studentScores;));
//        System.out.println("语文成绩最大为"+Collections.max(studentScores));
        StudentScore maxLgg = studentScores.get(0);

//        最终决定使用foreach循环
        for (StudentScore student : studentScores) {
            if (student.getLanguage() > maxLgg.getLanguage()) {
                maxLgg = student;
            }
        }
        System.out.println("语文成绩最大为: " + maxLgg.getLanguage());

        int sum = 0;
        for (StudentScore student : studentScores) {
            sum += student.getMath();
        }
//        int pjMach = Mach.getMath();
        int j = studentScores.size();

        System.out.println("数学平均分: " + sum / j);

        int[] men = new int[1];
        int[] women = new int[1];

        for (StudentScore student : studentScores) {
            if ("男".equals(student.getSex())) {
                men[0]++;
            } else if ("女".equals(student.getSex())) {
                women[0]++;
            }
        }

        System.out.println("男性数量: " + men[0]);
        System.out.println("女性数量: " + women[0]);

//        System.out.println(person);
//        String men = person.getSex();
//        System.out.println(men);
//     Collections.sort(studentScores, (A, B) -> A.getEnglish() - B.getEnglish());
//        System.out.println();
//        showAll();
//
//        TreeSet<StudentScore> sortedSet = new TreeSet<>();
//        sortedSet.addAll(studentScores);
//
//
//        for (StudentScore student : sortedSet) {
//            System.out.println(student);
//        }
//
        Collections.sort(studentScores, Comparator.comparingInt(StudentScore::getEnglish));
        showAll();
//        int[]En=new int[studentScores.size()];
//        for (int i = 0; i < studentScores.size(); i++) {
//            En[i] = studentScores.get(i).getEnglish();
//        }
//
//        // 打印排序后的英语成绩数组
//        System.out.println("排序后的英语成绩：");
//        for (int score : En) {
//            System.out.println(score);
//        }

//        int[] En= new int[studentScores.size()];
//
//        for (int i = 0; i < studentScores.size(); i++) {
//            En[i] = studentScores.get(i).getEnglish();
//        }
////        Collections.sort(En, (A, B) -> (A - B));
//        System.out.println("英语成绩：");
//        for (int score :En) {
//            System.out.println(score);
//        }
//
        System.out.println("----------");
        Collections.sort(studentScores,Comparator.comparingInt(StudentScore::getLanguage));
        showAll();
    }


    public static void showAll() {
        for (int i = 0; i < studentScores.size(); i++) {
            System.out.println(studentScores.get(i));
        }
    }}


